package com.gagakuai.bpm.common.aspect;



import com.gagakuai.bpm.common.annotation.HxDataSource;
import com.gagakuai.bpm.config.mybatisplus.config.DataSourceContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;

/*@Component
@Slf4j
@Aspect
@Order(-1)*/
@Slf4j
public class HxDataSourceAspect {

    @Pointcut("@within(com.linkcheers.mark.config.datasource.DataSource) || @annotation(com.linkcheers.mark.config.datasource.DataSource)")
    public void pointCut(){

    }

    @Before("pointCut() && @annotation(dataSource)")
    public void doBefore(HxDataSource dataSource){
        log.info("选择数据源---"+dataSource.value().getValue());
        DataSourceContextHolder.setDataSource(dataSource.value().getValue());
    }

    @After("pointCut()")
    public void doAfter(){
        DataSourceContextHolder.clear();
    }
}